<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ContractTemplate;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Actions\Post\Restore;
use App\Models\ContractTemplate as AppContractTemplate;

class ContractTemplateController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ContractTemplate(), function (Grid $grid) {
            $grid->disableDeleteButton();
            $grid->column('id', '序号')->sortable();
            $grid->column('title');
            // $grid->column('url');
            // $grid->column('remarks');
            // $grid->column('is_del');
            $grid->column('created_at')->sortable();
            // $grid->column('updated_at')->sortable();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                if (request('_scope_') == 'trashed') {
                    $actions->append(new Restore(AppContractTemplate::class));
                }
            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('title');
                $filter->scope('trashed', '回收站')->onlyTrashed();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ContractTemplate(), function (Show $show) {
            $show->disableDeleteButton();
            $show->field('id');
            $show->field('title');
            $show->url()->file();
            $show->field('remarks');
            // $show->field('is_del');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ContractTemplate(), function (Form $form) {
            $form->disableDeleteButton();
            $form->display('id');
            $form->text('title');
            $form->file('url', '上传模板')->disk('public')->autoUpload()->move('contract/template/' . date('Y/m') . '/' . uniqid())->required();
            $form->textarea('remarks');
            // $form->text('is_del');

            // $form->display('created_at');
            // $form->display('updated_at');
        });
    }
}
